package view;

import data.*;
import java.awt.*;

/**
 * 方块绘制视图类
 */
public class BlockView {
    // -------------------- view --------------------

    /**
     * 功能: 绘制方块
     * 参数:
     *   g: Graphics绘图对象
     *   block: 方块数据
     * 返回值: void
     */
    public void drawBlock(Graphics g, BlockData block) {
        if (block.getBlockKind() == 1) {
            // 砖块
            g.setColor(new Color(139, 69, 19)); // 棕色
            g.fillRect(block.getX(), block.getY(), block.getWidth(), block.getHeight());

            // 砖块纹理
            g.setColor(Color.BLACK);
            g.drawRect(block.getX(), block.getY(), block.getWidth(), block.getHeight());
            g.drawLine(block.getX(), block.getY() + 15, block.getX() + 30, block.getY() + 15);
            g.drawLine(block.getX() + 15, block.getY(), block.getX() + 15, block.getY() + 15);
            g.drawLine(block.getX() + 15, block.getY() + 15, block.getX() + 15, block.getY() + 30);

        } else if (block.getBlockKind() == 2) {
            // 铁块
            g.setColor(Color.GRAY);
            g.fillRect(block.getX(), block.getY(), block.getWidth(), block.getHeight());

            // 铁块纹理
            g.setColor(Color.DARK_GRAY);
            g.drawRect(block.getX(), block.getY(), block.getWidth(), block.getHeight());

            // 金属光泽效果
            g.setColor(Color.WHITE);
            g.drawLine(block.getX() + 2, block.getY() + 2, block.getX() + 28, block.getY() + 2);
            g.drawLine(block.getX() + 2, block.getY() + 2, block.getX() + 2, block.getY() + 28);

            g.setColor(Color.BLACK);
            g.drawLine(block.getX() + 28, block.getY() + 28, block.getX() + 2, block.getY() + 28);
            g.drawLine(block.getX() + 28, block.getY() + 28, block.getX() + 28, block.getY() + 2);
        }
    }
    // -------------------- view --------------------
}